package com.sk.bilibili.model.fragment.member;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.bean.FollowThem;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.dto.Page;
import com.sk.bilibili.mapper.FollowThemMapper;
import com.sk.bilibili.model.BaseModel;
import com.sk.bilibili.model.BaseRefreshModel;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.member.FollowThemFragment;

public class FollowThemModel extends BaseRefreshModel<FollowThemFragment> {

    @Autowired
    FollowThemMapper followThemMapper;
    private int page = 1;
    private int size = 15;

    public void refresh(Integer memberId) {
        page = 1;
        JsonMap map = getJsonMap(memberId);
        RequestUtils.process(followThemMapper.getFollowThem(map), followThemPage -> {
            view.refreshSuccess(followThemPage.getRecords());
            page++;
        });
    }

    private JsonMap getJsonMap(Integer memberId) {
        JsonMap map = new JsonMap();
        map.put("page", page);
        map.put("size", size);
        map.put("memberId", memberId);
        return map;
    }

    public void loadMore(Integer memberId) {
        JsonMap map = getJsonMap(memberId);
        RequestUtils.process(followThemMapper.getFollowThem(map), followThemPage -> {
            view.loadMoreSuccess(followThemPage.getRecords());
            page++;
        });
    }

}